package com.sk.bilibili.view.fragment.channel;

import android.view.View;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.sk.bilibili.adapter.vlayout.HeaderAdapter;
import com.sk.bilibili.adapter.vlayout.VideoSetAdapter;
import com.sk.bilibili.adapter.vlayout.channel.BannerAdapter;
import com.sk.bilibili.bean.Banner;
import com.sk.bilibili.bean.VideoSet;
import com.sk.bilibili.callBack.BannerClickCallBack;
import com.sk.bilibili.callBack.FullVideoSetCallBack;
import com.sk.bilibili.model.fragment.channel.VideoSetModel;
import com.sk.bilibili.utils.IntentUtils;
import com.sk.bilibili.view.activity.MemberActivity;
import com.sk.bilibili.view.activity.RankActivity;
import com.sk.bilibili.view.activity.VideoSetActivity;
import com.sk.bilibili.view.diy.bottomDialog.LaterBottomDialog;
import com.sk.bilibili.view.fragment.BaseTypeFragment;

import java.util.List;

public class FullVideoSetFragment extends BaseTypeFragment<VideoSetModel> implements FullVideoSetCallBack, BannerClickCallBack, View.OnClickListener {

    private Integer index;
    private LaterBottomDialog laterBottomDialog;

    public FullVideoSetFragment(Integer typeId, Integer index) {
        super(typeId);
        this.index=index;
        laterBottomDialog=new LaterBottomDialog();
    }

    private BannerAdapter bannerAdapter;
    private VideoSetAdapter videoSetAdapter;

    @Override
    protected void initAdapter(DelegateAdapter adapter) {
        bannerAdapter = new BannerAdapter(getContext(), this);
        adapter.addAdapter(bannerAdapter);
        adapter.addAdapter(new HeaderAdapter(getContext(),this));
        videoSetAdapter = new VideoSetAdapter(getContext(), this);
        adapter.addAdapter(videoSetAdapter);
    }

    @Override
    public void onBottom() {
        model.loadMore(typeId);
    }

    @Override
    public void onRefresh() {
        model.refresh(typeId);
        model.loadBanner(typeId);
    }

    @Override
    public void onClickVideoSet(Integer id) {
        VideoSetActivity.start(getContext(),id);
    }

    @Override
    public void onClickMember(Integer id) {
        MemberActivity.start(getContext(),id);
    }

    @Override
    public void onClickMore(Integer id) {
        laterBottomDialog.show(getChildFragmentManager(),id);
    }

    public void loadMoreSuccess(List<VideoSet> records) {
        if(records.isEmpty()){
            toast("没有更多数据了");
            return;
        }
        videoSetAdapter.addData(records);
    }

    public void refreshSuccess(List<VideoSet> records) {
        videoSetAdapter.setData(records);
        cancelRefresh();
    }

    @Override
    public void onBannerClick(String url) {
        IntentUtils.startUrl(getContext(),url);
    }

    @Override
    public void onClick(View v) {
        RankActivity.start(getContext(),index);
    }

    public void loadBannerSuccess(List<Banner> banners) {
        bannerAdapter.setList(banners);
    }

}